<?php
include_once('models/cateproduct_model.php');
include_once('models/categories_model.php');
include_once('models/productfront_model.php');
include_once('models/articles_model.php');
include_once('controllers/backend_controller.php');
include_once('controllers/frontend_controller.php');

class Pagehome_Controller extends Frontend_Controller {
	public $model;
	public $model2;
	public $action = 'lists';

	public function __construct(){
		parent::__construct();
		$this->model = new Cateproduct_Model();
		$this->model2 = new Categories_Model();
		$this->model3 = new Productfront_Model();
		$this->model4 = new Articles_Model();
		if(isset($_GET['action'])) $this->action = $_GET['action'];
		$this->{$this->action}();
	}
	public function lists(){
		$listCategoriesPro = $this->model->getListCate();
		$listCategories = $this->model2->getListCate();
		include 'views/home/home.php';
	}
	public function getAllProductForACat(){
		$listCategoriesPro = $this->model->getListCate();
		$listCategories = $this->model2->getListCate();
		$cat=$_GET['name'];
		$CatPro =  $this->model3->getAllProForACat($cat);
		//Var_dump($CatPro);exit();
		include 'views/product/listaCatforProductfront.php';
	}
	
	public function getAllReportInACat(){
		$listCategoriesPro = $this->model->getListCate();
		$listCategories = $this->model2->getListCate();
		$cat=$_GET['name'];
		$Art =  $this->model4->getAllArtInACat($cat);
		//Var_dump($CatPro);exit();
		include 'views/product/ArticleList.php';
	}
	public function getAProduct() {
		$listCategoriesPro = $this->model->getListCate();
		$listCategories = $this->model2->getListCate();
		$id=$_GET['id'];
		$CatPro =  $this->model3->getAPro($id);
		//Var_dump($CatPro);exit();
		include 'views/product/displayAProduct.php';
	}
	public function getAArtcle() {
		$listCategoriesPro = $this->model->getListCate();
		$listCategories = $this->model2->getListCate();
		$id=$_GET['id'];
		$Article =  $this->model4->getAArticle($id);
		//Var_dump($CatPro);exit();
		include 'views/product/displayAArticle.php';
	}
	public function listAllProduct() {
		$id=$_GET['id'];
		$artPro = $this->model->getListProductforEachcat($id);
		include 'views/product/product-lists.php';
	}
	public function view() {
		$id = $_GET['id'];
		//exit($id);
		$viewProductCat =  $this->model->viewCat($id);
		//var_dump($viewProductCat); exit();
		include 'views/categories/viewProductCat.php';
	}
	public function add() {
		if(isset($_POST["btn_submit"])) { 
			if(($_POST['nameCat'] != '') && ($_POST['descr'] != '')){
				$nameCat = $_POST['nameCat'];
				$description = $_POST['descr'];
				$addCat = $this->model->addCat($nameCat,$description);
				header ('Location: index.php?controller=cateproduct&action=lists');
			} 
			else 
			{
				include 'views/categories/addcatProduct.php';
			}
		}
		else 
		{
			include 'views/categories/addcatProduct.php';
		}
	}
	public function edit() {
		if(isset($_POST["btn_submit"])){ 
			if(isset($_POST['nameCat']) && (isset($_POST['descr']))) {
				$nameCat = $_POST['nameCat'];
				$description = $_POST['descr'];
				$id = $_POST['id'];
				$editCat = $this->model->editCat($nameCat,$description,$id);
				header ('Location: index.php?controller=cateproduct&action=lists');
			}
		}
		else{
				$id = $_GET['id'];
				$beforeditCat = $this->model->beforeditCat($id);
				include 'views/categories/editCatPro.php';
			}
	}
	public function delete() {
		$id = $_GET['id'];
		$delCat = $this->model->delCat($id);
		header ('Location: index.php?controller=cateproduct&action=lists');
	} 
}
?>